const CompanyStudentModel = require("../model/CompanyStudentModel")

const CompanyStudentService = {
    getList:async () => {
        //联系role集合查询
        return await CompanyStudentModel.find()
    },
    addList:async (body) => {
        // return CompanyStudentModel.create(body)
        for(let i of body){
            await CompanyStudentModel.findOneAndUpdate({
                //限制唯一相同的字段，保证不会重复添加
                studentname:i.studentname,
                company:i.company
            },{
                $set:i
            },{
                upsert:true
            })
        }
        return []
    },
    deleteList:async(id) => {
        //删除所有包含classid的数据
        return await CompanyStudentModel.deleteMany({class:id})
    },
    // updateList:async(id,{key,value}) => {
    //     return await CompanyStudentModel.findByIdAndUpdate(id,{
    //         "$set":{
    //             ["score."+key]:value
    //         }
    //     })
    // }
}
module.exports = CompanyStudentService